import java.util.Random;

public class text {

    private static int[] array = new int[10000000];
    private static long evenNum = 0;
    private static long oddNum = 0;
    public static void main(String[] args) throws InterruptedException {
        long startTime = System.currentTimeMillis();
        Thread mainThread = Thread.currentThread();
        Random random = new Random();

        Thread intoThread = new Thread(()->{
            for (int i = 0; i < array.length; i++) {
                int num = random.nextInt(100);
                array[i] = num;
            }
        });
        intoThread.start();
        intoThread.join();

        Thread t1 = new Thread(()->{
            for (int i = 0; i < array.length; i+=2) {
                evenNum += array[i];
            }
        });

        Thread t2 = new Thread(()->{
            for (int i = 1; i < array.length; i+=2) {
                oddNum += array[i];
            }
        });

        t1.start();

        t2.start();
        t1.join();
        t2.join();


        long endTime = System.currentTimeMillis();
        System.out.println("偶数下标和为："+evenNum);
        System.out.println("奇数下标和为："+oddNum);
        System.out.println("数组总和为：" + (oddNum + evenNum));
        System.out.println("总耗时为：" + (endTime - startTime));
    }
}
